package org.apache.jsp.view.comprar.medicamento;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.jsp.*;
import br.com.skpharma.vo.*;
import br.com.skpharma.dao.*;
import java.util.*;
import java.text.SimpleDateFormat;

public final class index_jsp extends org.apache.jasper.runtime.HttpJspBase
    implements org.apache.jasper.runtime.JspSourceDependent {

  private static final JspFactory _jspxFactory = JspFactory.getDefaultFactory();

  private static java.util.List _jspx_dependants;

  private javax.el.ExpressionFactory _el_expressionfactory;
  private org.apache.AnnotationProcessor _jsp_annotationprocessor;

  public Object getDependants() {
    return _jspx_dependants;
  }

  public void _jspInit() {
    _el_expressionfactory = _jspxFactory.getJspApplicationContext(getServletConfig().getServletContext()).getExpressionFactory();
    _jsp_annotationprocessor = (org.apache.AnnotationProcessor) getServletConfig().getServletContext().getAttribute(org.apache.AnnotationProcessor.class.getName());
  }

  public void _jspDestroy() {
  }

  public void _jspService(HttpServletRequest request, HttpServletResponse response)
        throws java.io.IOException, ServletException {

    PageContext pageContext = null;
    HttpSession session = null;
    ServletContext application = null;
    ServletConfig config = null;
    JspWriter out = null;
    Object page = this;
    JspWriter _jspx_out = null;
    PageContext _jspx_page_context = null;


    try {
      response.setContentType("text/html; charset=iso-8859-1");
      pageContext = _jspxFactory.getPageContext(this, request, response,
      			null, true, 8192, true);
      _jspx_page_context = pageContext;
      application = pageContext.getServletContext();
      config = pageContext.getServletConfig();
      session = pageContext.getSession();
      out = pageContext.getOut();
      _jspx_out = out;

      out.write("\r\n");
      out.write("\r\n");
      out.write("\r\n");
      out.write("<html>\r\n");
      out.write("\r\n");
      out.write("\r\n");
      out.write("<script language=\"JavaScript\">\r\n");
      out.write("function buscaLab(valor)\r\n");
      out.write("{\r\n");
      out.write(" \twindow.location.href=\"index.jsp?lab=\" + valor.value;\r\n");
      out.write("}\r\n");
      out.write("function buscaPrin(valor)\r\n");
      out.write("{\r\n");
      out.write(" \twindow.location.href=\"index.jsp?prin=\" + valor.value;\r\n");
      out.write("}\r\n");
      out.write("</script>\r\n");
      out.write("  \r\n");
      out.write("  \r\n");
      out.write("<head>\r\n");
      out.write("<title></title>\r\n");
      out.write("<link href=\"../css/css.css\" rel=\"stylesheet\" type=\"text/css\">\r\n");
      out.write("<link href=\"../../css/css.css\" rel=\"stylesheet\" type=\"text/css\">\r\n");
      out.write("<style type=\"text/css\">\r\n");
      out.write("<!--\r\n");
      out.write(".style1 {color: #FFFFFF}\r\n");
      out.write(".style3 {color: #FFFFFF; font-weight: bold; }\r\n");
      out.write("body {\r\n");
      out.write("\tmargin-left: 0px;\r\n");
      out.write("\tmargin-top: 0px;\r\n");
      out.write("\tmargin-right: 0px;\r\n");
      out.write("\tmargin-bottom: 0px;\r\n");
      out.write("}\r\n");
      out.write("a:link {\r\n");
      out.write("\tcolor: #000000;\r\n");
      out.write("\ttext-decoration: none;\r\n");
      out.write("}\r\n");
      out.write("a:visited {\r\n");
      out.write("\tcolor: #000000;\r\n");
      out.write("\ttext-decoration: none;\r\n");
      out.write("}\r\n");
      out.write("a:active {\r\n");
      out.write("\tcolor: #000000;\r\n");
      out.write("\ttext-decoration: none;\r\n");
      out.write("}\r\n");
      out.write("a:hover {\r\n");
      out.write("\tcolor: #999999;\r\n");
      out.write("\ttext-decoration: none;\r\n");
      out.write("}\r\n");
      out.write("-->\r\n");
      out.write("</style>\r\n");
      out.write("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\"></head>\r\n");
      out.write("\r\n");
      out.write("<body>\r\n");
      out.write("<p align=\"left\"><strong><br>\r\n");
      out.write("Medicamentos</strong></p>\r\n");
      out.write("<form method=\"POST\" action=\"index.jsp\" >\r\n");
      out.write("  <table width=\"700\" border=\"0\" align=\"left\" cellpadding=\"5\" cellspacing=\"2\" bordercolor=\"#f2f2f2\" style=\"font-size:12px\">\r\n");
      out.write("  <tr>\r\n");
      out.write("    <td width=\"30%\" bgcolor=\"#941C1D\"><p class=\"style1\"><strong>Nome:\r\n");
      out.write("    \r\n");
      out.write("          <input style=\"font-size:12px\" type=\"text\" name=\"txtNome\" size=\"13\">    \r\n");
      out.write("          <input type=\"submit\" value=\"Buscar\" name=\"buscaNome\" style=\"font:Verdana, Arial, Helvetica, sans-serif; font-size:10px\">\r\n");
      out.write("    \r\n");
      out.write("    </strong></p>    </td>   \r\n");
      out.write("\t\r\n");
      out.write("\t<td width=\"5%\" bgcolor=\"#941C1D\"><span class=\"style3\">Conte&uacute;do</span></td>\r\n");
      out.write("    <td width=\"5%\" bgcolor=\"#941C1D\"><span class=\"style3\">Preço</span></td>\r\n");
      out.write("    <td width=\"23%\" bgcolor=\"#941C1D\"><p class=\"style3\">Laboratorio:\r\n");
      out.write("    \r\n");
      out.write("    <select style=\"font-size:12px\" name=\"laboratorio\" onkeypress=\"javascript:buscaLab(this)\" >\r\n");
      out.write("\r\n");
      out.write("    ");

      		DAOLaboratorio daoLaboratorio = new DAOLaboratorio();
      		ArrayList lista3 = new ArrayList();
      		lista3 = daoLaboratorio.obterLista();		
      		for (int i = 0; i<lista3.size(); i++){
      
      out.write("\r\n");
      out.write("      \t\t<option value=\"");
      out.print(((LaboratorioVO)lista3.get(i)).getCod());
      out.write('"');
      out.write('>');
      out.print(((LaboratorioVO)lista3.get(i)).getDs());
      out.write("</option>\r\n");
      out.write("\t  ");

        }
	  
      out.write("      \r\n");
      out.write("          </select>\r\n");
      out.write("        \r\n");
      out.write("      </p>    </td>\r\n");
      out.write("   \r\n");
      out.write("    <td width=\"29%\" bgcolor=\"#941C1D\"><p class=\"style3\">Principio Ativo:\r\n");
      out.write("    \r\n");
      out.write("    <select style=\"font-size:12px\" name=\"principioativo\" onkeypress=\"javascript:buscaPrin(this)\">\r\n");
      out.write("    ");

      		DAOPrincipioAtivo daoPrincipioAtivo = new DAOPrincipioAtivo();
      		ArrayList lista2 = new ArrayList();
      		lista2 = daoPrincipioAtivo.obterLista();		
      		for (int i = 0; i<lista2.size(); i++){
      
      out.write("\r\n");
      out.write("      \t\t<option value=\"");
      out.print(((PrincipioAtivoVO)lista2.get(i)).getCod());
      out.write('"');
      out.write('>');
      out.print(((PrincipioAtivoVO)lista2.get(i)).getDs());
      out.write("</option>\r\n");
      out.write("\t  ");

        }
	  
      out.write("      \r\n");
      out.write("          </select>\r\n");
      out.write("        \r\n");
      out.write("      </p>    </td>\r\n");
      out.write("  </tr>\r\n");
      out.write(" \r\n");
      out.write(" \r\n");

if (request.getParameter("prin") != null){
	int codigo = Integer.valueOf(request.getParameter("prin"));
	DAOMedicamento daoMedicamento = new DAOMedicamento();
	ArrayList lista = new ArrayList();
	lista = daoMedicamento.buscaPrincipioAtivo(codigo);
	for (int i = 0; i<lista.size(); i++){

      out.write("\r\n");
      out.write("  \t\t<tr>\r\n");
      out.write("  \t\t\t\r\n");
      out.write("\t\t    <td width=\"15%\"><a href=\"detalhe.jsp?cod_med=");
      out.print(((MedicamentoVO)lista.get(i)).getCod());
      out.write('"');
      out.write('>');
      out.print(((MedicamentoVO)lista.get(i)).getDs());
      out.write("</a></td>\r\n");
      out.write("\t\t    <td width=\"7%\">");
      out.print(((MedicamentoVO)lista.get(i)).getConteudo());
      out.write("</td>\r\n");
      out.write("\t\t    <td width=\"7%\">");
      out.print(((MedicamentoVO)lista.get(i)).getPreco());
      out.write("</td>\r\n");
      out.write("\t\t    <td width=\"7%\">");
      out.print(((MedicamentoVO)lista.get(i)).getLaboratorioVO().getDs());
      out.write("</td>\r\n");
      out.write("\t\t    <td width=\"7%\">");
      out.print(((MedicamentoVO)lista.get(i)).getPrincipioAtivoVO().getDs());
      out.write("</td>\r\n");
      out.write("\t</tr>\r\n");
      out.write("\t");
		
	}		
}else 
if (request.getParameter("lab") != null){
	int codigo = Integer.valueOf(request.getParameter("lab"));
	DAOMedicamento daoMedicamento = new DAOMedicamento();
	ArrayList lista = new ArrayList();
	lista = daoMedicamento.buscaLaboratorio(codigo);
	for (int i = 0; i<lista.size(); i++){

      out.write("\r\n");
      out.write("  \t\t<tr>\r\n");
      out.write("  \t\t\t\r\n");
      out.write("\t\t    <td width=\"15%\"><a href=\"detalhe.jsp?cod_med=");
      out.print(((MedicamentoVO)lista.get(i)).getCod());
      out.write('"');
      out.write('>');
      out.print(((MedicamentoVO)lista.get(i)).getDs());
      out.write("</a></td>\r\n");
      out.write("\t\t    <td width=\"7%\">");
      out.print(((MedicamentoVO)lista.get(i)).getConteudo());
      out.write("</td>\r\n");
      out.write("\t\t    <td width=\"7%\">");
      out.print(((MedicamentoVO)lista.get(i)).getPreco());
      out.write("</td>\r\n");
      out.write("\t\t    <td width=\"7%\">");
      out.print(((MedicamentoVO)lista.get(i)).getLaboratorioVO().getDs());
      out.write("</td>\r\n");
      out.write("\t\t    <td width=\"7%\">");
      out.print(((MedicamentoVO)lista.get(i)).getPrincipioAtivoVO().getDs());
      out.write("</td>\r\n");
      out.write("\t</tr>\r\n");
      out.write("\t");
		
	}		
}else
if (request.getParameter("txtNome") != ""){
if(request.getParameter("buscaNome") != null){
	String nome = request.getParameter("txtNome");
	DAOMedicamento daoMedicamento = new DAOMedicamento();
	ArrayList lista = new ArrayList();
	lista = daoMedicamento.buscaNome(nome);
	for (int i = 0; i<lista.size(); i++){

      out.write("\r\n");
      out.write("  \t\t<tr>\r\n");
      out.write("  \t\t\r\n");
      out.write("\t\t    <td width=\"15%\"><a href=\"detalhe.jsp?cod_med=");
      out.print(((MedicamentoVO)lista.get(i)).getCod());
      out.write('"');
      out.write('>');
      out.print(((MedicamentoVO)lista.get(i)).getDs());
      out.write("</a></td>\r\n");
      out.write("\t\t    <td width=\"7%\">");
      out.print(((MedicamentoVO)lista.get(i)).getConteudo());
      out.write("</td>\r\n");
      out.write("\t\t    <td width=\"7%\">");
      out.print(((MedicamentoVO)lista.get(i)).getPreco());
      out.write("</td>\r\n");
      out.write("\t\t    <td width=\"7%\">");
      out.print(((MedicamentoVO)lista.get(i)).getLaboratorioVO().getDs());
      out.write("</td>\r\n");
      out.write("\t\t    <td width=\"7%\">");
      out.print(((MedicamentoVO)lista.get(i)).getPrincipioAtivoVO().getDs());
      out.write("</td>\r\n");
      out.write("\t</tr>\r\n");
      out.write("\t");
		
	}
}		
}else
{


      out.write("\r\n");
      out.write("\r\n");

DAOMedicamento daoMedicamento = new DAOMedicamento();
ArrayList lista = new ArrayList();
lista = daoMedicamento.obterLista();		
for (int i = 0; i<lista.size(); i++){

      out.write("\r\n");
      out.write("  \t\t<tr>\r\n");
      out.write("  \t\t\t\r\n");
      out.write("\t\t    <td width=\"15%\"><a href=\"detalhe.jsp?cod_med=");
      out.print(((MedicamentoVO)lista.get(i)).getCod());
      out.write('"');
      out.write('>');
      out.print(((MedicamentoVO)lista.get(i)).getDs());
      out.write("</a></td>\r\n");
      out.write("\t\t    <td width=\"7%\">");
      out.print(((MedicamentoVO)lista.get(i)).getConteudo());
      out.write("</td>\r\n");
      out.write("\t\t    <td width=\"7%\">");
      out.print(((MedicamentoVO)lista.get(i)).getPreco());
      out.write("</td>\r\n");
      out.write("\t\t    <td width=\"7%\">");
      out.print(((MedicamentoVO)lista.get(i)).getLaboratorioVO().getDs());
      out.write("</td>\r\n");
      out.write("\t\t    <td width=\"7%\">");
      out.print(((MedicamentoVO)lista.get(i)).getPrincipioAtivoVO().getDs());
      out.write("</td>\r\n");
      out.write("\t</tr>\r\n");
		
}
}

      out.write("\r\n");
      out.write("</table>\r\n");
      out.write("</form>\r\n");
      out.write("</body>\r\n");
      out.write("</html>\r\n");
      out.write("\r\n");
    } catch (Throwable t) {
      if (!(t instanceof SkipPageException)){
        out = _jspx_out;
        if (out != null && out.getBufferSize() != 0)
          try { out.clearBuffer(); } catch (java.io.IOException e) {}
        if (_jspx_page_context != null) _jspx_page_context.handlePageException(t);
      }
    } finally {
      _jspxFactory.releasePageContext(_jspx_page_context);
    }
  }
}
